﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>登陆日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="name" placeholder="请输入用户名" autocomplete="new-password"
                               class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" layadmin-event="reset">
                            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="form-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="loginlog-manage" lay-filter="loginlog-manage"></table>
            </div>
        </div>
    </div>
    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'table'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table

            var areaName = "loginlog-manage";
            var field = {};
            //监听搜索
            form.on('submit(form-search)', function (data) {
                field = data.field;
                //执行重载
                table.reload(areaName, {
                    where: { queryJson: JSON.stringify(field) },
                    page: {
                        curr: 1
                    }
                });
            });
            //管理
            table.render({
                elem: '#' + areaName,
                url: '/api/LoginInfo/GetLoginInfoPageList',
                cols: [
                    [
                        { field: 'number', title: '序号', width: 100, align: 'center', type: 'numbers' },
                        { field: 'cTitle', title: '标题', width: 100, align: 'center', templet: (r) => '登陆' },
                        { field: 'cIp', title: 'IP', minWidth: 100, align: 'center', },
                        { field: 'cAddress', title: '地址', minWidth: 100, align: 'center', },
                        { field: 'cBrowserName', title: '浏览器', width: 150, align: 'center', templet: (r) => r.cBrowserName + r.cBrowserVersion },
                        { field: 'cOSName', title: '系统', width: 150, align: 'center', templet: (r) => r.cOSName + r.cOSVersion },
                        { field: 'cUser', title: '登陆用户', align: 'center', width: 150 },
                        { field: 'cCreatedDate', title: '时间', align: 'center', width: 180 }
                    ]
                ],
                page: true,
                limit: 20,
                height: 'full-110',
                text: '对不起，加载出现异常！',
                done: function (res) {
                    if (res.count === 0) {
                        $(".layui - table - main").html("暂无数据");
                    }
                    let that = this;
                    // 右键操作
                    layui.dropdown.render({
                        elem: `.layui-table-view[lay-id="${that.id}"] .layui-table-body tr`,
                        trigger: 'contextmenu',
                        show: true,
                        data: [
                            { title: '功能1', id: 'event1', templet: (d) => '<div><i class="layui-icon layui-icon-tips"></> ' + d.title + '</div>' },
                            { title: '功能2', id: 'event2', templet: (d) => '<div><i class="layui-icon layui-icon-tips"></> ' + d.title + '</div>' }
                        ],
                        click(data, othis) {
                            // 获取表格当前行数据
                            let trData = table.cache[that.id][this.elem.data('index')];
                            alert(data.id)
                        }
                    });
                    //改变行颜色
                    var that_table = this.elem.next();
                    res.entitys?.forEach(function (item, index) {
                        var tr = that_table.find("[data-index=" + index + "]").children();
                        let cIp = tr.eq(2).text();
                        if (cIp.indexOf('127.0.0.1') != -1) {
                            $(tr.eq(2)).css('background-color', "#D3E3FD");
                        }
                    })
                }
            });
            var selectRow = null;
            table.on('row(' + areaName + ')', function (obj) {
                selectRow = obj.data;
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            });
        });
    </script>
</body>

</html>